//
//  NovelSiftSecondTableViewCell.m
//  novel
//
//  Created by Tracy on 2018/8/11.
//  Copyright © 2018年 Tracy. All rights reserved.
//

#import "NovelSiftSecondTableViewCell.h"
#import "novelSecondModel.h"
@interface NovelSiftSecondTableViewCell()
@property (nonatomic, strong) UILabel * manLabel ;
@property (nonatomic, strong) UILabel * manTitleLabel ;
@property (nonatomic, strong) UILabel * girlLabel;
@property (nonatomic, strong) UILabel * girlTitleLabel ;
@end
@implementation NovelSiftSecondTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self addSubview:self.manLabel];
        [self.manLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(20 * kProportionW);
            make.top.equalTo(self).offset(10 * kProportionW);
            make.height.equalTo(@(25 * kProportionW));
        }];
        
        [self addSubview:self.manTitleLabel];
        [self.manTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.manLabel);
            make.top.equalTo(self.manLabel.mas_bottom);
            make.height.equalTo(@(25 * kProportionW));
        }];
        
        [self addSubview:self.firstBtn];
        [self.firstBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(20 * kProportionW);
            make.top.equalTo(self.manTitleLabel.mas_bottom).offset(10 * kProportionW);
            make.height.equalTo(@(70 * kProportionW));
            make.width.equalTo(@(kScreenW/2 - 30 * kProportionW));
        }];
        
        [self addSubview:self.girlLabel];
        [self.girlLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(kScreenW/2 + 10 * kProportionW);
            make.top.equalTo(self).offset(10 * kProportionW);
            make.height.equalTo(@(25 * kProportionW));
        }];
        
        [self addSubview:self.girlTitleLabel];
        [self.girlTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.girlLabel);
            make.top.equalTo(self.girlLabel.mas_bottom);
            make.height.equalTo(@(25 * kProportionW));
        }];
        
        [self addSubview:self.secondBtn];
        [self.secondBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.girlTitleLabel);
            make.top.equalTo(self.girlTitleLabel.mas_bottom).offset(10 * kProportionW);
            make.height.equalTo(@(70 * kProportionW));
            make.width.equalTo(@(kScreenW/2 - 30 * kProportionW));
        }];
        
//
//        UIView * view1 =  [self addViewTitle:@"虚构" desc:@"高分佳作" pic:@""];
//        [self addSubview:view1];
//        [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(self.secondBtn.mas_bottom).offset(20 * kProportionW);
//            make.left.equalTo(self);
//            make.height.equalTo(@(100*kProportionW));
//            make.width.equalTo(@(kScreenW/4));
//        }];
//
//        UIView * view2 =  [self addViewTitle:@"短篇" desc:@"板栗好书" pic:@""];
//        [self addSubview:view2];
//        [view2 mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(self.secondBtn.mas_bottom).offset(20 * kProportionW);
//            make.left.equalTo(view1.mas_right);
//            make.height.equalTo(@(100*kProportionW));
//            make.width.equalTo(@(kScreenW/4));
//        }];
//
//        UIView * view3 =  [self addViewTitle:@"漫画" desc:@"免费追番" pic:@""];
//        [self addSubview:view3];
//        [view3 mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(self.secondBtn.mas_bottom).offset(20 * kProportionW);
//            make.left.equalTo(view2.mas_right);
//            make.height.equalTo(@(120*kProportionW));
//            make.width.equalTo(@((kScreenW/2 - 100 * kProportionW)/2));
//        }];
//
//        UIView * view4 =  [self addViewTitle:@"积木" desc:@"8.9元小课" pic:@""];
//        [self addSubview:view4];
//        [view4 mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(self.secondBtn.mas_bottom).offset(20 * kProportionW);
//            make.left.equalTo(view3.mas_right);
//            make.height.equalTo(@(100*kProportionW));
//            make.width.equalTo(@(kScreenW/4));
//        }];
    }
    return self;
}

- (void)setDataArray:(NSArray *)dataArray
{
    _dataArray = dataArray;
    novelSecondModel * manModel = dataArray[0];
    [self.manLabel setText:manModel.name];
    [self.manTitleLabel setText:manModel.desc];
    [self.firstBtn sd_setImageWithURL:[NSURL URLWithString:manModel.pic] forState:UIControlStateNormal];
    
    novelSecondModel * girlModel = dataArray[1];
    [self.girlLabel setText:girlModel.name];
    [self.girlTitleLabel setText:girlModel.desc];
    [self.secondBtn sd_setImageWithURL:[NSURL URLWithString:girlModel.pic] forState:UIControlStateNormal];
    
    for (int i = 2; i < dataArray.count; i++) {
        novelSecondModel * otherModel = dataArray[i];
        UIView * view1 =  [self addViewTitle:otherModel.name desc:otherModel.desc  pic:otherModel.pic];
        view1.tag = i;
        [self addSubview:view1];
        [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.secondBtn.mas_bottom).offset(20 * kProportionW);
            make.left.equalTo(self).offset(20 * kProportionW + (40 * kProportionW) * (i - 2) + (kScreenW/2 - 80 * kProportionW)/2 * (i - 2));
            make.height.equalTo(@(110*kProportionW));
            make.width.equalTo(@((kScreenW/2 - 80 * kProportionW)/2));
        }];
        
        
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick:)];
        tap.delegate = self;
        [view1 addGestureRecognizer:tap];
    }
    
    
    
    
}


- (void)tapClick:(UITapGestureRecognizer *)tap{
    UITapGestureRecognizer *singleTap = (UITapGestureRecognizer *)tap;
    NSInteger index = singleTap.view.tag;
    NSLog(@"--index=%ld----",index);
}

- (void)manNovelClick{
    NSLog(@"--男生小说---");
}

- (void)girlNovelClick{
    NSLog(@"--女生小说---");
}

-(UIView *)addViewTitle:(NSString *)title desc:(NSString *)desc pic:(NSString *)pic {
    UIView *sectionView = [UIView new];
    UILabel * titleLabel = [UILabel new];
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.font = [UIFont boldSystemFontOfSize:15 * kProportionW];
    titleLabel.textAlignment = NSTextAlignmentLeft;
    titleLabel.text = title;
    [sectionView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(sectionView);
        make.left.equalTo(sectionView);
        make.height.equalTo(@(10* kProportionW));
    }];
    UILabel *descLabel = [UILabel new];
    descLabel.text = desc;
    descLabel.font = [UIFont systemFontOfSize:12 * kProportionW];
    descLabel.textColor = TINTCOLOR;
    descLabel.textAlignment = NSTextAlignmentLeft;
    [sectionView addSubview:descLabel];
    [descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLabel.mas_bottom).offset(10* kProportionW);
        make.left.equalTo(sectionView);
        make.height.equalTo(@(10* kProportionW));
    }];
    UIImageView * imageView = [[UIImageView alloc]init];
    [imageView sd_setImageWithURL:[NSURL URLWithString:pic]];
    imageView.userInteractionEnabled = YES;
    [sectionView addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(descLabel.mas_bottom).offset(10* kProportionW);
        make.left.equalTo(sectionView);
        make.right.equalTo(sectionView);
        make.bottom.equalTo(sectionView);
    }];
    
    return sectionView;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

#pragma mark -- lazy load
- (UILabel *)manLabel {
    if(!_manLabel){
        _manLabel = [UILabel new];
        _manLabel.text = @"男生小说";
        _manLabel.textColor = [UIColor blackColor];
        _manLabel.font = [UIFont boldSystemFontOfSize:16 * kProportionW];
        _manLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _manLabel;
}

- (UILabel *)manTitleLabel {
    if(!_manTitleLabel){
        _manTitleLabel = [UILabel new];
        _manTitleLabel.text = @"都市 玄幻 仙侠 历史";
        _manTitleLabel.font = [UIFont systemFontOfSize:13 * kProportionW];
        _manTitleLabel.textColor = TINTCOLOR;
        _manTitleLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _manTitleLabel;
}

- (UIButton *)firstBtn {
    if(!_firstBtn){
        _firstBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _firstBtn.adjustsImageWhenHighlighted = NO;
        [_firstBtn addTarget:self action:@selector(manNovelClick) forControlEvents:UIControlEventTouchUpInside];
    }
   return  _firstBtn;
}

- (UILabel *)girlLabel {
    if(!_girlLabel){
        _girlLabel = [UILabel new];
        _girlLabel.text = @"女生小说";
        _girlLabel.textColor = [UIColor blackColor];
        _girlLabel.font = [UIFont boldSystemFontOfSize:16 * kProportionW];
        _girlLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _girlLabel;
}

- (UILabel *)girlTitleLabel{
    if(!_girlTitleLabel){
        _girlTitleLabel = [UILabel new];
        _girlTitleLabel.text = @"总裁 豪门 穿越 重生";
        _girlTitleLabel.font = [UIFont systemFontOfSize:13 * kProportionW];
        _girlTitleLabel.textColor = TINTCOLOR;
        _girlTitleLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _girlTitleLabel;
}

- (UIButton *)secondBtn {
    if(!_secondBtn){
        _secondBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _secondBtn.adjustsImageWhenHighlighted = NO;
        [_secondBtn addTarget:self action:@selector(girlNovelClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return  _secondBtn;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
